//
//  GoodsTitleView.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/25.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "GoodsTitleView.h"
#import "MarkLabel.h"

@interface GoodsTitleView ()

@property (strong, nonatomic) MarkLabel *logoL;


@end

@implementation GoodsTitleView

- (instancetype)init {
    
    if (self = [super init]) {
        
        self.backgroundColor = WhiteColor;

        [self addSubview:self.logoL];
        [self addSubview:self.titleL];
        
 
    }
    
    return self;
}

- (void)setTitleStr:(NSString *)titleStr {
    
    _titleStr = titleStr;
 
    NSString *titileStr = titleStr;
    
//    NSString *titileStr = @"GUCCI 古驰 女士Ace休闲真皮镶钻版小白鞋一箭穿心图案";
    
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:titileStr];
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineSpacing = jisuan(12);
    paraStyle.firstLineHeadIndent = jisuan(60);
    
    [attributeStr addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, attributeStr.length)];
    //
    self.titleL.attributedText = attributeStr;
    self.titleL.lineBreakMode = NSLineBreakByTruncatingTail;
    
    
    const float kFontSize = jisuan(30);
    
    NSStringDrawingOptions options =  NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    
    CGRect rect = [titleStr boundingRectWithSize:CGSizeMake(WIDTH - jisuan(50),MAXFLOAT) options:options attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kFontSize]} context:nil];
    
    CGFloat realHeight = ceilf(rect.size.height);
    
    if (self.heigt) {
        self.heigt(realHeight + 35);
    }
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    
    [self.logoL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left).with.offset(jisuan(20));
        make.top.mas_equalTo(weakSelf.mas_top).with.offset(jisuan(40));
        make.width.mas_equalTo(jisuan(54));
        make.height.mas_equalTo(jisuan(30));
        
    }];
  
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left).with.offset(jisuan(20));
        make.right.mas_equalTo(weakSelf.mas_right).with.offset(-jisuan(20));
        make.top.mas_equalTo(weakSelf.mas_top).with.offset(jisuan(36));
//        make.bottom.mas_equalTo(weakSelf.mas_bottom).with.offset(-jisuan(36));
        
    }];
 
}

#pragma mark -lazy


- (MarkLabel *)logoL {
    
    if (!_logoL) {

        _logoL = [[MarkLabel alloc] init];
        _logoL.textColor = Colorff0000;
        _logoL.font = [UIFont systemFontOfSize:jisuan(16)];
        _logoL.textAlignment = NSTextAlignmentCenter;
        
        _logoL.text = @"自营";
        _logoL.layer.borderWidth = jisuan(2);
        _logoL.layer.borderColor = Colorff0000.CGColor;
        _logoL.layer.cornerRadius = jisuan(15);
        _logoL.layer.masksToBounds = YES;
        
    }
    
    return _logoL;
}


- (UILabel *)titleL {
    
    if (!_titleL) {
        
        _titleL = [[UILabel alloc] init];
        _titleL.numberOfLines = 2;
        _titleL.font = [UIFont fontWithName:@"Helvetica-Bold" size:jisuan(30)];
//        _titleL.lineBreakMode = NSLineBreakByTruncatingTail;
    
//        NSString *titileStr = @"GUCCI 古驰 女士Ace休闲真皮镶钻版小白鞋一箭穿心图案";
//
//        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:titileStr];
//
//        NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
//        paraStyle.lineSpacing = jisuan(20);
//        paraStyle.firstLineHeadIndent = jisuan(60);
//
//        [attributeStr addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, attributeStr.length)];
////
//        _titleL.attributedText = attributeStr;
        
    }
    
    return _titleL;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
